/**
 * Created by Administrator on 2018/4/26.
 */
define(function (require,exports,module) {
    require("./enter.css");
    var sTpl = require("./template.html");
    var VueComponent = Vue.extend({
        props:['parentData'],
        template: sTpl,
        methods:{
            saveAppointment :function(){
                var $this = this ;
                this.$refs["formData"].validate(function(valid) {
                    if (valid) {
                        var data = JSON.parse(JSON.stringify($this.formData));
                        if(!data.agreement.contractManageId){
                            data.agreement=null;
                        }
                        axios.post(basepath+'/api/appointment/addAppointment',data)
                            .then(function (response) {
                                $this.$refs["formData"].resetFields();
                                $this.$notify({
                                    title: '添加成功',
                                    message: '添加成功'
                                });
                        });
                            return true;
                    } else {
                            return false;
                    }
            });
            },
            editAppointment :function(){
                var $this = this ;
                this.$refs["formData"].validate(function(valid) {
                    if (valid) {
                        var data = JSON.parse(JSON.stringify($this.formData));
                        if(!data.agreement.contractManageId){
                            data.agreement=null;
                        }
                        axios.post(basepath+'/api/appointment/editAppointment',data)
                            .then(function (response) {
                                $this.parentData.dataCallBack(response.data);
                                $this.$notify({
                                    title: '修改成功',
                                    message: '修改成功'
                                });
                            });
                        return true;
                    } else {
                        return false;
                    }
                });
            },
            passAppointment :function(status){
                var $this = this ;
                if(status=="")
                this.$confirm('确定要通过审核？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    $this.formData.status=status;
                    axios.post(basepath+'/api/appointment/editAppointment',$this.formData)
                        .then(function (response) {
                            $this.parentData.dataCallBack(response.data);
                            $this.$notify({
                                title: '审核通过',
                                message: '改预约已通过审核'
                            });
                        });
                })
            },
            onSubmit: function () {
                console.log('submit!');
            },
            querySearchUnit:function(queryString, cb) {
                var restaurants = this.units;
                var results = queryString ? restaurants.filter(function(restaurant){
                        return restaurant?restaurant.value?(restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0):false:false;
                }) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            querySearchPlace:function(queryString, cb) {
                var restaurants = this.place;
                console.log(this.form);
                var results = queryString ? restaurants.filter(function(restaurant){
                    return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                }) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            querySearchContract:function(queryString, cb) {
                var restaurants = this.contracts;
                var results = queryString ? restaurants.filter(function(restaurant){
                    return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                }) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            contractChange:function (value) {
                if(!value){
                    this.contract={};
                }else{
                    this.contract=this.contracts.filter(function (data) {
                        if(data.contractManageId == value){
                            return data;
                        }
                    })[0];
                }


            },
            querySearchFlightNumber:function(queryString, cb) {
                var restaurants = this.flightNumber;
                var results = queryString ? restaurants.filter(function(restaurant){
                    return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                }) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
    },

            handleSelect:function(item) {
                console.log(item);
            },
            returnParent:function(){
                this.parentData.returnParent();
            }
        },
        mounted:function() {
            var $this = this;
            axios.get(basepath+"/api/appointment/findAllAppoUnit").then(function (response) {
                response.data.forEach(function (data) {
                    $this.units.push({value:data})
                })

            })
        }
        ,data:function(){

            return {
                currentAppointment:{
                    appoUnit:"123",
                    appoName:"123"
                }, form: {
                    unit: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                    flightNumber:''
                },
                formData:{
                    appo_id :"",
                    address :"",
                    aircraftGuidMark :"",
                    aircraftSpecialServiceMark :"",
                    appProperty :"",
                    appoDate :"",
                    appoEmil :"",
                    agreement:{contractManageId:""},
                    appoName :"",
                    appoPhoneNum :null,
                    appoUnit :"",
                    baggageHandlingMark :"",
                    businessircraftRoomMark :"",
                    carToApronMark :"",
                    civilAviationControlCommandMark :"",
                    contactName :"",
                    contactPhoneNum :"",
                    corporateAircraftSpecialWayMark :"",
                    customsBorderControl :"",
                    destination :"",
                    exPassagewayMarks :"",
                    ferryPushreMarks :"",
                    flightNum :"",
                    flightInfo:{flightInfoId:''},
                    flightProperty :"",
                    gasolineMark :"",
                    guideMark :"",
                    hasPersonNum :"",
                    hasContactInfo:false,
                    needAircraftGuide :false,
                    needAircraftSpecialService :false,
                    needBaggageHandlng :false,
                    needBusinessAircraftRoom :false,
                    needCar :false,
                    needCarToApron :false,
                    needBaggageHandling:false,
                    needCivilAviationControlCommand :false,
                    needCorporateAircraftSpecialWay :false,
                    needCustomsBorderControl :false,
                    needExitPassageway :false,
                    needFerryPush :false,
                    needGasoline :false,
                    needGuide :false,
                    needOther :false,
                    originating :"",
                    otherMark :"",
                    personNum :"",
                    status:"未审核"

        },
               contract:{},
                flights:[],
                units: [],
                contracts:[],
                flightNumber:[{value:"N95"},{value:"98k"}],
                activeNames: ['1'],
                place:[{value:'北京'},
                    {value:'天津'},
                    {value:'上海'},
                    {value:'徐州'},
                    {value:'常州 '},
                    {value:'江苏'},
                    {value:'南通'},
                    {value:'无锡'},
                    {value:'南京'},
                    {value:'连云港'},
                    {value:'济南'},
                    {value:'临沂'},
                    {value:'潍坊'},
                    {value:'威海'},
                    {value:'烟台'},
                    {value:'青岛'},
                    {value:'济宁'},
                    {value:'黄岩路'},
                    {value:'衢州'},
                    {value:'舟山'},
                    {value:'宁波'},
                    {value:'温州'},
                    {value:'杭州'},
                    {value:'锦州'},
                    {value:'朝阳'},
                    {value:'沈阳'},
                    {value:'大连'},
                    {value:'赤峰'},
                    {value:'内蒙古'},
                    {value:'锡林浩特'},
                    {value:'包头'},
                    {value:'呼和浩特'},
                    {value:'乌兰浩特'},
                    {value:'海拉尔'},
                    {value:'乌海'},
                    {value:'呼伦贝尔'},
                    {value:'通辽'},
                    {value:'南平市'},
                    {value:'厦门'},
                    {value:'泉州'},
                    {value:'晋江'},
                    {value:'福州'},
                    {value:'黄山屯溪'},
                    {value:'安庆'},
                    {value:'合肥'},
                    {value:'阜阳'},
                    {value:'蚌埠'},
                    {value:'嘉峪关'},
                    {value:'酒泉'},
                    {value:'庆阳'},
                    {value:'兰州'},
                    {value:'深圳'},
                    {value:'珠海'},
                    {value:'梅县'},
                    {value:'湛江'},
                    {value:'汕头'},
                    {value:'北海福城'},
                    {value:'广西'},
                    {value:'梧州'},
                    {value:'柳州'},
                    {value:'南宁'},
                    {value:'桂林'},
                    {value:'贵州'},
                    {value:'兴义'},
                    {value:'铜仁'},
                    {value:'黎平'},
                    {value:'龙洞堡'},
                    {value:'荔波'},
                    {value:'海口'},
                    {value:'三亚'},
                    {value:'秦皇岛'},
                    {value:'邯郸'},
                    {value:'邢台'},
                    {value:'石家庄'},
                    {value:'洛阳'},
                    {value:'南阳'},
                    {value:'郑州'},
                    {value:'黑河'},
                    {value:'佳木斯'},
                    {value:'哈尔滨'},
                    {value:'齐齐哈尔'},
                    {value:'牡丹江'},
                    {value:'武汉'},
                    {value:'宜昌'},
                    {value:'襄樊'},
                    {value:'恩施'},
                    {value:'常德'},
                    {value:'张家界'},
                    {value:'长沙'},
                    {value:'怀化'},
                    {value:'延吉'},
                    {value:'长白山'},
                    {value:'吉林'},
                    {value:'长春'},
                    {value:'德镇'},
                    {value:'井冈山'},
                    {value:'九江庐山'},
                    {value:'吉安'},
                    {value:'南昌'},
                    {value:'赣州'},
                    {value:'银川'},
                    {value:'西宁'},
                    {value:'格尔木'},
                    {value:'运城'},
                    {value:'太原'},
                    {value:'大同'},
                    {value:'长治'},
                    {value:'西安'},
                    {value:'安康'},
                    {value:'延安'},
                    {value:'榆林'},
                    {value:'汉中'},
                    {value:'成都'},
                    {value:'康定'},
                    {value:'达县'},
                    {value:'西昌'},
                    {value:'绵阳'},
                    {value:'四川攀枝花'},
                    {value:'九寨沟'},
                    {value:'广汉'},
                    {value:'南充'},
                    {value:'宜宾'},
                    {value:'林芝'},
                    {value:'昌都邦达'},
                    {value:'拉萨贡嘎'},
                    {value:'阿勒泰'},
                    {value:'伊宁'},
                    {value:'喀纳斯'},
                    {value:'喀什'},
                    {value:'库尔勒'},
                    {value:'克拉玛依'},
                    {value:'库车'},
                    {value:'且末'},
                    {value:'富蕴'},
                    {value:'和田'},
                    {value:'哈密'},
                    {value:'伊犁那拉提'},
                    {value:'鄯善'},
                    {value:'塔城'},
                    {value:'乌鲁木齐'},
                    {value:'阿克苏'},
                    {value:'景洪'},
                    {value:'昭通'},
                    {value:'文山普者黑'},
                    {value:'普洱'},
                    {value:'大理'},
                    {value:'丽江'},
                    {value:'云南迪庆香格里拉'},
                    {value:'德宏芒市'},
                    {value:'昆明巫家坝'},
                    {value:'重庆'},
                    {value:'香港'},
                    {value:'澳门'},
                    {value:'台北'},
                    {value:'桃园'},
                    {value:'台中'},
                    {value:'台东'},
                    {value:'台南'}]

            }
        },
        created:function (){
            var $this = this;
            axios.get("/dam/api/flightInfo/queryFlightInfo?filter=").then(function (response) {
                $this.flights=response.data;
            })
            axios.get("/dam/api/sysSetting/checkContractManage").then(function (response) {
                $this.contracts=response.data;
            })

             //else{
            //     if(this.parentData.showOrEdit=="show"){
            //         messages.$emit('change','预约信息详情');
            //     }else{
            //         messages.$emit('change','预约信息修改');
            //     }
            // }
        },
        activated:function () {
            if(!this.parentData){
                messages.$emit('change','预约信息录入');
            }
        }
    });

    module.exports = VueComponent;
})